/*
 * @Descripttion: 
 * @version: 
 * @Author: 周志伟
 * @Date: 2021-06-07 15:05:36
 * @LastEditors: 周志伟
 * @LastEditTime: 2021-06-11 16:10:39
 */
var FS = require("fire-fs"), PATH = require("fire-path"), fse = require("fs-extra");

/** 包名 */
const PACKAGE_NAME = 'zzw_quate';

Editor.Panel.extend({
  /** HTML */
  template: FS.readFileSync(Editor.url(`packages://${PACKAGE_NAME}/panel.partial/index.html`), 'utf8'),

  /** 样式 */
  style: FS.readFileSync(Editor.url(`packages://${PACKAGE_NAME}/panel.partial/index.css`), 'utf8'),


  // method executed when template and styles are successfully loaded and initialized
  ready() {
    // 创建 Vue 实例
    new window.Vue({
      created() {
        Editor.log("created");
      },
      /**
       * 挂载目标
       * @type {string | Element}
       */
      el: this.shadowRoot,
      /**
           * 数据对象
           */
      data: {
        // 多语言文本
        titleLabel: "预制题查找",
        findLabel: "查找",
        // 资源 uuid
        uuid: '',
        // 按钮状态
        isProcessing: false,
        secenesJson: null,
        dependencyList: []
      },

      watch: {
        secenesJson: function () {
          // this.creatDependency()
        }
      },

      /**
       * 实例函数
       * @type {{ [key: string]: Function }}
       */
      methods: {
        creatDependency() {
          Editor.log('json', this.secenesJson)
          var b = Editor.remote.assetdb.uuidToUrl(this.secenesJson).split("/");
          var assetName = b[b.length - 1]
          Editor.log('json', assetName)
          var secenesJsonInfo = Editor.assetdb.remote.assetInfoByUuid(this.secenesJson);
          Editor.log(secenesJsonInfo, 'json信息')
          var jsonInfo = FS.readJsonSync(secenesJsonInfo.path)

          Editor.log('zzzzzzzzzzzzzzzz', jsonInfo)

          let tibanList = jsonInfo.filter(item => {
            if (item.__type__ == 'cc.Node') {

              if (item._parent === null) {
                Editor.log('222222222222', item._components)
              }
              return item._name;
            }
          })
          Editor.log('111111', tibanList)


          // let tibanList = seceneList.filter(page => {
          //     return page.type == 'prefab'
          // })
          // tibanList.forEach(tiban => {
          //     const path = Editor.url('db://assets/resources/' + tiban.path, "utf8")
          //     this.findDependency(path)

          // })

        },

        resetCkickBtn() {
          Editor.log('按钮状态重置');

          this.isProcessing = false;
        },
        /**
         * 查找
         */
        onFindPartialBtnClick() {
          if (this.isProcessing) return;
          this.isProcessing = false;
          // uuid
          const uuid = this.secenesJson;

          // 发消息给主进程
          Editor.Ipc.sendToMain(`${PACKAGE_NAME}:find-partial-quate`, uuid, (error) => {
            Editor.log('onFindBtnClick 发消息给主进程!');
          });
        },
      },
    });
  }
});